home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / CIncludes / SCSI.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-12  |  51.0 KB  |  1,056 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        SCSI.h
  3.  
  4.      Contains:    SCSI Family Interfaces.
  5.  
  6.      Version:    Technology:    SCSI 4.3
  7.                  Release:    Universal Interfaces 3.0.1
  8.  
  9.      Copyright:    © 1986-1997 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __SCSI__
  19. #define __SCSI__
  20.  
  21. #ifndef __TYPES__
  22. #include <Types.h>
  23. #endif
  24. #ifndef __MIXEDMODE__
  25. #include <MixedMode.h>
  26. #endif
  27.  
  28.  
  29.  
  30. #if PRAGMA_ONCE
  31. #pragma once
  32. #endif
  33.  
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37.  
  38. #if PRAGMA_IMPORT
  39. #pragma import on
  40. #endif
  41.  
  42. #if PRAGMA_STRUCT_ALIGN
  43.     #pragma options align=mac68k
  44. #elif PRAGMA_STRUCT_PACKPUSH
  45.     #pragma pack(push, 2)
  46. #elif PRAGMA_STRUCT_PACK
  47.     #pragma pack(2)
  48. #endif
  49.  
  50. /* SCSI Manager errors. These are generated by Inside Mac IV calls only. */
  51.  
  52. enum {
  53.     scCommErr                    = 2,                            /* communications error, operation timeout */
  54.     scArbNBErr                    = 3,                            /* arbitration timeout waiting for not BSY */
  55.     scBadParmsErr                = 4,                            /* bad parameter or TIB opcode */
  56.     scPhaseErr                    = 5,                            /* SCSI bus not in correct phase for attempted operation */
  57.     scCompareErr                = 6,                            /* data compare error */
  58.     scMgrBusyErr                = 7,                            /* SCSI Manager busy  */
  59.     scSequenceErr                = 8,                            /* attempted operation is out of sequence */
  60.     scBusTOErr                    = 9,                            /* CPU bus timeout */
  61.     scComplPhaseErr                = 10                            /* SCSI bus wasn't in Status phase */
  62. };
  63.  
  64. /* TIB opcodes */
  65.  
  66. enum {
  67.     scInc                        = 1,
  68.     scNoInc                        = 2,
  69.     scAdd                        = 3,
  70.     scMove                        = 4,
  71.     scLoop                        = 5,
  72.     scNop                        = 6,
  73.     scStop                        = 7,
  74.     scComp                        = 8
  75. };
  76.  
  77. /* Signatures */
  78.  
  79. enum {
  80.     sbSIGWord                    = 0x4552,                        /* signature word for Block 0 ('ER') */
  81.     sbMac                        = 1,                            /* system type for Mac */
  82.     pMapSIG                        = 0x504D,                        /* partition map signature ('PM') */
  83.     pdSigWord                    = 0x5453
  84. };
  85.  
  86.  
  87. enum {
  88.     oldPMSigWord                = pdSigWord,
  89.     newPMSigWord                = pMapSIG
  90. };
  91.  
  92. /* Driver Descriptor Map */
  93. struct Block0 {
  94.     unsigned short                     sbSig;                        /* unique value for SCSI block 0 */
  95.     unsigned short                     sbBlkSize;                    /* block size of device */
  96.     unsigned long                     sbBlkCount;                    /* number of blocks on device */
  97.     unsigned short                     sbDevType;                    /* device type */
  98.     unsigned short                     sbDevId;                    /* device id */
  99.     unsigned long                     sbData;                        /* not used */
  100.     unsigned short                     sbDrvrCount;                /* driver descriptor count */
  101.     unsigned long                     ddBlock;                    /* 1st driver's starting block */
  102.     unsigned short                     ddSize;                        /* size of 1st driver (512-byte blks) */
  103.     unsigned short                     ddType;                        /* system type (1 for Mac+) */
  104.     unsigned short                     ddPad[243];                    /* ARRAY[0..242] OF INTEGER; not used */
  105. };
  106. typedef struct Block0 Block0;
  107.  
  108. /* Driver descriptor */
  109. struct DDMap {
  110.     unsigned long                     ddBlock;                    /* 1st driver's starting block */
  111.     unsigned short                     ddSize;                        /* size of 1st driver (512-byte blks) */
  112.     unsigned short                     ddType;                        /* system type (1 for Mac+) */
  113. };
  114. typedef struct DDMap DDMap;
  115.  
  116. /* Partition Map Entry */
  117. struct Partition {
  118.     unsigned short                     pmSig;                        /* unique value for map entry blk */
  119.     unsigned short                     pmSigPad;                    /* currently unused */
  120.     unsigned long                     pmMapBlkCnt;                /* # of blks in partition map */
  121.     unsigned long                     pmPyPartStart;                /* physical start blk of partition */
  122.     unsigned long                     pmPartBlkCnt;                /* # of blks in this partition */
  123.     unsigned char                     pmPartName[32];                /* ASCII partition name */
  124.     unsigned char                     pmParType[32];                /* ASCII partition type */
  125.     unsigned long                     pmLgDataStart;                /* log. # of partition's 1st data blk */
  126.     unsigned long                     pmDataCnt;                    /* # of blks in partition's data area */
  127.     unsigned long                     pmPartStatus;                /* bit field for partition status */
  128.     unsigned long                     pmLgBootStart;                /* log. blk of partition's boot code */
  129.     unsigned long                     pmBootSize;                    /* number of bytes in boot code */
  130.     unsigned long                     pmBootAddr;                    /* memory load address of boot code */
  131.     unsigned long                     pmBootAddr2;                /* currently unused */
  132.     unsigned long                     pmBootEntry;                /* entry point of boot code */
  133.     unsigned long                     pmBootEntry2;                /* currently unused */
  134.     unsigned long                     pmBootCksum;                /* checksum of boot code */
  135.     unsigned char                     pmProcessor[16];            /* ASCII for the processor type */
  136.     unsigned short                     pmPad[188];                    /* ARRAY[0..187] OF INTEGER; not used */
  137. };
  138. typedef struct Partition Partition;
  139.  
  140. /* TIB instruction */
  141. struct SCSIInstr {
  142.     unsigned short                     scOpcode;
  143.     long                             scParam1;
  144.     long                             scParam2;
  145. };
  146. typedef struct SCSIInstr SCSIInstr;
  147.  
  148. /* SCSI Phases (used by SIMs to support the Original SCSI Manager */
  149.  
  150. enum {
  151.     kDataOutPhase                = 0,                            /* Encoded MSG, C/D, I/O bits */
  152.     kDataInPhase                = 1,
  153.     kCommandPhase                = 2,
  154.     kStatusPhase                = 3,
  155.     kPhaseIllegal0                = 4,
  156.     kPhaseIllegal1                = 5,
  157.     kMessageOutPhase            = 6,
  158.     kMessageInPhase                = 7,
  159.     kBusFreePhase                = 8,                            /* Additional Phases */
  160.     kArbitratePhase                = 9,
  161.     kSelectPhase                = 10,
  162.     kMessageInPhaseNACK            = 11                            /* Message In Phase with ACK hanging on the bus */
  163. };
  164.  
  165.  
  166. EXTERN_API( OSErr )
  167. SCSIReset                        (void)                                                        TWOWORDINLINE(0x4267, 0xA815);
  168.  
  169. EXTERN_API( OSErr )
  170. SCSIGet                            (void)                                                        THREEWORDINLINE(0x3F3C, 0x0001, 0xA815);
  171.  
  172. EXTERN_API( OSErr )
  173. SCSISelect                        (short                     targetID)                            THREEWORDINLINE(0x3F3C, 0x0002, 0xA815);
  174.  
  175. EXTERN_API( OSErr )
  176. SCSICmd                            (Ptr                     buffer,
  177.                                  short                     count)                                THREEWORDINLINE(0x3F3C, 0x0003, 0xA815);
  178.  
  179. EXTERN_API( OSErr )
  180. SCSIRead                        (Ptr                     tibPtr)                                THREEWORDINLINE(0x3F3C, 0x0005, 0xA815);
  181.  
  182. EXTERN_API( OSErr )
  183. SCSIRBlind                        (Ptr                     tibPtr)                                THREEWORDINLINE(0x3F3C, 0x0008, 0xA815);
  184.  
  185. EXTERN_API( OSErr )
  186. SCSIWrite                        (Ptr                     tibPtr)                                THREEWORDINLINE(0x3F3C, 0x0006, 0xA815);
  187.  
  188. EXTERN_API( OSErr )
  189. SCSIWBlind                        (Ptr                     tibPtr)                                THREEWORDINLINE(0x3F3C, 0x0009, 0xA815);
  190.  
  191. EXTERN_API( OSErr )
  192. SCSIComplete                    (short *                stat,
  193.                                  short *                message,
  194.                                  unsigned long             wait)                                THREEWORDINLINE(0x3F3C, 0x0004, 0xA815);
  195.  
  196. EXTERN_API( short )
  197. SCSIStat                        (void)                                                        THREEWORDINLINE(0x3F3C, 0x000A, 0xA815);
  198.  
  199. EXTERN_API( OSErr )
  200. SCSISelAtn                        (short                     targetID)                            THREEWORDINLINE(0x3F3C, 0x000B, 0xA815);
  201.  
  202. EXTERN_API( OSErr )
  203. SCSIMsgIn                        (short *                message)                            THREEWORDINLINE(0x3F3C, 0x000C, 0xA815);
  204.  
  205. EXTERN_API( OSErr )
  206. SCSIMsgOut                        (short                     message)                            THREEWORDINLINE(0x3F3C, 0x000D, 0xA815);
  207.  
  208.  
  209.  
  210. enum {
  211.     scsiVERSION                    = 43
  212. };
  213.  
  214.  
  215. /*
  216.  * SCSI Callback Procedure Prototypes. Several of these are only callable
  217.  * from SCSI Manager 4.3 SIM and XPT contexts. 
  218.  */
  219. typedef CALLBACK_API_C( void , AENCallbackProcPtr )(void );
  220. typedef CALLBACK_API_C( OSErr , SIMInitProcPtr )(Ptr SIMinfoPtr);
  221. typedef CALLBACK_API_C( void , SIMActionProcPtr )(void *scsiPB, Ptr SIMGlobals);
  222. typedef CALLBACK_API_C( void , SCSIProcPtr )(void );
  223. typedef CALLBACK_API_C( void , SCSIMakeCallbackProcPtr )(void *scsiPB);
  224. /* SCSIInterruptPollProcPtr is obsolete (use SCSIInterruptProcPtr) but still here for compatibility */
  225. typedef CALLBACK_API_C( long , SCSIInterruptPollProcPtr )(Ptr SIMGlobals);
  226. typedef CALLBACK_API_C( long , SCSIInterruptProcPtr )(Ptr SIMGlobals);
  227. typedef STACK_UPP_TYPE(AENCallbackProcPtr)                         AENCallbackUPP;
  228. typedef STACK_UPP_TYPE(SIMInitProcPtr)                             SIMInitUPP;
  229. typedef STACK_UPP_TYPE(SIMActionProcPtr)                         SIMActionUPP;
  230. typedef STACK_UPP_TYPE(SCSIProcPtr)                             SCSIUPP;
  231. typedef STACK_UPP_TYPE(SCSIMakeCallbackProcPtr)                 SCSIMakeCallbackUPP;
  232. typedef STACK_UPP_TYPE(SCSIInterruptPollProcPtr)                 SCSIInterruptPollUPP;
  233. typedef STACK_UPP_TYPE(SCSIInterruptProcPtr)                     SCSIInterruptUPP;
  234. typedef CALLBACK_API( void , SCSICallbackProcPtr )(void *scsiPB);
  235. typedef STACK_UPP_TYPE(SCSICallbackProcPtr)                     SCSICallbackUPP;
  236. enum { uppAENCallbackProcInfo = 0x00000001 };                     /* no_return_value Func() */
  237. enum { uppSIMInitProcInfo = 0x000000E1 };                         /* 2_bytes Func(4_bytes) */
  238. enum { uppSIMActionProcInfo = 0x000003C1 };                     /* no_return_value Func(4_bytes, 4_bytes) */
  239. enum { uppSCSIProcInfo = 0x00000001 };                             /* no_return_value Func() */
  240. enum { uppSCSIMakeCallbackProcInfo = 0x000000C1 };                 /* no_return_value Func(4_bytes) */
  241. enum { uppSCSIInterruptPollProcInfo = 0x000000F1 };             /* 4_bytes Func(4_bytes) */
  242. enum { uppSCSIInterruptProcInfo = 0x000000F1 };                 /* 4_bytes Func(4_bytes) */
  243. enum { uppSCSICallbackProcInfo = 0x000000C0 };                     /* pascal no_return_value Func(4_bytes) */
  244. #define NewAENCallbackProc(userRoutine)                         (AENCallbackUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppAENCallbackProcInfo, GetCurrentArchitecture())
  245. #define NewSIMInitProc(userRoutine)                             (SIMInitUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSIMInitProcInfo, GetCurrentArchitecture())
  246. #define NewSIMActionProc(userRoutine)                             (SIMActionUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSIMActionProcInfo, GetCurrentArchitecture())
  247. #define NewSCSIProc(userRoutine)                                 (SCSIUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSIProcInfo, GetCurrentArchitecture())
  248. #define NewSCSIMakeCallbackProc(userRoutine)                     (SCSIMakeCallbackUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSIMakeCallbackProcInfo, GetCurrentArchitecture())
  249. #define NewSCSIInterruptPollProc(userRoutine)                     (SCSIInterruptPollUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSIInterruptPollProcInfo, GetCurrentArchitecture())
  250. #define NewSCSIInterruptProc(userRoutine)                         (SCSIInterruptUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSIInterruptProcInfo, GetCurrentArchitecture())
  251. #define NewSCSICallbackProc(userRoutine)                         (SCSICallbackUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppSCSICallbackProcInfo, GetCurrentArchitecture())
  252. #define CallAENCallbackProc(userRoutine)                         CALL_ZERO_PARAMETER_UPP((userRoutine), uppAENCallbackProcInfo)
  253. #define CallSIMInitProc(userRoutine, SIMinfoPtr)                 CALL_ONE_PARAMETER_UPP((userRoutine), uppSIMInitProcInfo, (SIMinfoPtr))
  254. #define CallSIMActionProc(userRoutine, scsiPB, SIMGlobals)         CALL_TWO_PARAMETER_UPP((userRoutine), uppSIMActionProcInfo, (scsiPB), (SIMGlobals))
  255. #define CallSCSIProc(userRoutine)                                 CALL_ZERO_PARAMETER_UPP((userRoutine), uppSCSIProcInfo)
  256. #define CallSCSIMakeCallbackProc(userRoutine, scsiPB)             CALL_ONE_PARAMETER_UPP((userRoutine), uppSCSIMakeCallbackProcInfo, (scsiPB))
  257. #define CallSCSIInterruptPollProc(userRoutine, SIMGlobals)         CALL_ONE_PARAMETER_UPP((userRoutine), uppSCSIInterruptPollProcInfo, (SIMGlobals))
  258. #define CallSCSIInterruptProc(userRoutine, SIMGlobals)             CALL_ONE_PARAMETER_UPP((userRoutine), uppSCSIInterruptProcInfo, (SIMGlobals))
  259. #define CallSCSICallbackProc(userRoutine, scsiPB)                 CALL_ONE_PARAMETER_UPP((userRoutine), uppSCSICallbackProcInfo, (scsiPB))
  260. /* SCSI Manager 4.3 function codes */
  261.  
  262. enum {
  263.     SCSINop                        = 0x00,                            /* Execute nothing                                         */
  264.     SCSIExecIO                    = 0x01,                            /* Execute the specified IO                             */
  265.     SCSIBusInquiry                = 0x03,                            /* Get parameters for entire path of HBAs                 */
  266.     SCSIReleaseQ                = 0x04,                            /* Release the frozen SIM queue for particular LUN         */
  267.     SCSIAbortCommand            = 0x10,                            /* Abort the selected Control Block                      */
  268.     SCSIResetBus                = 0x11,                            /* Reset the SCSI bus                                      */
  269.     SCSIResetDevice                = 0x12,                            /* Reset the SCSI device                                  */
  270.     SCSITerminateIO                = 0x13,                            /* Terminate any pending IO                              */
  271.     SCSIGetVirtualIDInfo        = 0x80,                            /* Find out which bus old ID is on                         */
  272.     SCSILoadDriver                = 0x82,                            /* Load a driver for a device ident                     */
  273.     SCSIOldCall                    = 0x84,                            /* XPT->SIM private call for old-API                     */
  274.     SCSICreateRefNumXref        = 0x85,                            /* Register a DeviceIdent to drvr RefNum xref             */
  275.     SCSILookupRefNumXref        = 0x86,                            /* Get DeviceIdent to drvr RefNum xref                     */
  276.     SCSIRemoveRefNumXref        = 0x87,                            /* Remove a DeviceIdent to drvr RefNum xref             */
  277.     SCSIRegisterWithNewXPT        = 0x88,                            /* XPT has changed - SIM needs to re-register itself     */
  278.     vendorUnique                = 0xC0                            /* 0xC0 thru 0xFF */
  279. };
  280.  
  281.  
  282. /* Allocation length defines for some of the fields */
  283.  
  284. enum {
  285.     handshakeDataLength            = 8,                            /* Handshake data length */
  286.     maxCDBLength                = 16,                            /* Space for the CDB bytes/pointer */
  287.     vendorIDLength                = 16                            /* ASCII string len for Vendor ID  */
  288. };
  289.  
  290. /* Define DeviceIdent structure */
  291. struct DeviceIdent {
  292.     UInt8                             diReserved;                    /* reserved                 */
  293.     UInt8                             bus;                        /* SCSI - Bus Number        */
  294.     UInt8                             targetID;                    /* SCSI - Target SCSI ID    */
  295.     UInt8                             LUN;                        /* SCSI - LUN                  */
  296. };
  297. typedef struct DeviceIdent DeviceIdent;
  298.  
  299. /* Command Descriptor Block structure */
  300. union CDB {
  301.     BytePtr                         cdbPtr;                        /* pointer to the CDB, or */
  302.     UInt8                             cdbBytes[16];                /* the actual CDB to send */
  303. };
  304. typedef union CDB CDB;
  305.  
  306. typedef CDB *                            CDBPtr;
  307. /* Scatter/gather list element (Deprecated for MacOS8) */
  308. struct SGRecord {
  309.     Ptr                             SGAddr;
  310.     UInt32                             SGCount;
  311. };
  312. typedef struct SGRecord SGRecord;
  313.  
  314.  
  315. #define SCSIPBHdr                         \
  316.     struct SCSIHdr* qLink;                \
  317.     short            scsiReserved1;        \
  318.     UInt16            scsiPBLength;        \
  319.     UInt8            scsiFunctionCode;    \
  320.     UInt8            scsiReserved2;        \
  321.     volatile OSErr    scsiResult;            \
  322.     DeviceIdent        scsiDevice;            \
  323.     SCSICallbackUPP    scsiCompletion;        \
  324.     UInt32            scsiFlags;            \
  325.     UInt8 *            scsiDriverStorage;    \
  326.     Ptr                scsiXPTprivate;        \
  327.     long            scsiReserved3;
  328.  
  329. struct SCSIHdr {
  330.     struct SCSIHdr *                qLink;                        /* (internal use, must be nil on entry)    */
  331.     short                             scsiReserved1;                /* ->     reserved for input                */
  332.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  333.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  334.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  335.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  336.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  337.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  338.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  339.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  340.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  341.     long                             scsiReserved3;                /* reserved                                */
  342. };
  343. typedef struct SCSIHdr SCSIHdr;
  344.  
  345. struct SCSI_PB {
  346.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  347.     short                             scsiReserved1;                /* ->     reserved for input                */
  348.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  349.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  350.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  351.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  352.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  353.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  354.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  355.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  356.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  357.     long                             scsiReserved3;                /* reserved                                */
  358. };
  359. typedef struct SCSI_PB SCSI_PB;
  360.  
  361. struct SCSI_IO {
  362.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  363.     short                             scsiReserved1;                /* ->     reserved for input                */
  364.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  365.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  366.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  367.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  368.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  369.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  370.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  371.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  372.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  373.     long                             scsiReserved3;                /* reserved                                */
  374.  
  375.     UInt16                             scsiResultFlags;            /* <- Flags which modify the scsiResult field        */
  376.     UInt16                             scsiReserved3pt5;            /* -> Reserved                                        */
  377.     BytePtr                         scsiDataPtr;                /* -> Pointer to the data buffer or the S/G list      */
  378.     UInt32                             scsiDataLength;                /* -> Data transfer length                            */
  379.     BytePtr                         scsiSensePtr;                /* -> Ptr to autosense data buffer                  */
  380.     UInt8                             scsiSenseLength;            /* -> size of the autosense buffer                     */
  381.     UInt8                             scsiCDBLength;                /* -> Number of bytes for the CDB                      */
  382.     UInt16                             scsiSGListCount;            /* -> num of scatter gather list entries              */
  383.     UInt32                             scsiReserved4;                /* <-     reserved for output                            */
  384.     UInt8                             scsiSCSIstatus;                /* <- Returned scsi device status                      */
  385.     SInt8                             scsiSenseResidual;            /* <- Autosense residual length                      */
  386.     UInt16                             scsiReserved5;                /* <-     reserved for output                             */
  387.     long                             scsiDataResidual;            /* <- Returned Transfer residual length              */
  388.     CDB                             scsiCDB;                    /* -> Actual CDB or pointer to CDB                  */
  389.     long                             scsiTimeout;                /* -> Timeout value (Time Mgr format) (CAM timeout) */
  390.     BytePtr                         scsiReserved5pt5;            /* -> Reserved                                        */
  391.     UInt16                             scsiReserved5pt6;            /* -> Reserved                                        */
  392.     UInt16                             scsiIOFlags;                /* -> additional I/O flags                               */
  393.     UInt8                             scsiTagAction;                /* -> What to do for tag queuing                       */
  394.     UInt8                             scsiReserved6;                /* ->     reserved for input                             */
  395.     UInt16                             scsiReserved7;                /* ->     reserved for input                             */
  396.     UInt16                             scsiSelectTimeout;            /* -> Select timeout value                             */
  397.     UInt8                             scsiDataType;                /* -> Data description type (i.e. buffer, TIB, S/G)    */
  398.     UInt8                             scsiTransferType;            /* -> Transfer type (i.e. Blind vs Polled)             */
  399.     UInt32                             scsiReserved8;                /* ->     reserved for input                             */
  400.     UInt32                             scsiReserved9;                /* ->     reserved for input                             */
  401.     UInt16                             scsiHandshake[8];            /* -> handshaking points (null term'd)    */
  402.     UInt32                             scsiReserved10;                /* ->     reserved for input                             */
  403.     UInt32                             scsiReserved11;                /* ->   reserved for input                            */
  404.     struct SCSI_IO *                scsiCommandLink;            /* -> Ptr to the next PB in linked cmd chain         */
  405.  
  406.     UInt8                             scsiSIMpublics[8];            /* ->     reserved for input to 3rd-party SIMs        */
  407.     UInt8                             scsiAppleReserved6[8];        /* ->    reserved for input                              */
  408.  
  409.                                                                 /* XPT layer privates (for old-API emulation) */
  410.  
  411.     UInt16                             scsiCurrentPhase;            /* <- phase upon completing old call                  */
  412.     short                             scsiSelector;                /* -> selector specified in old calls                  */
  413.     OSErr                             scsiOldCallResult;            /* <- result of old call                              */
  414.     UInt8                             scsiSCSImessage;            /* <- Returned scsi device message (for SCSIComplete)*/
  415.     UInt8                             XPTprivateFlags;            /* <> various flags                                   */
  416.     UInt8                             XPTextras[12];                /*                                                    */
  417. };
  418. typedef struct SCSI_IO SCSI_IO;
  419.  
  420. typedef SCSI_IO                         SCSIExecIOPB;
  421. /* Bus inquiry PB */
  422. struct SCSIBusInquiryPB {
  423.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  424.     short                             scsiReserved1;                /* ->     reserved for input                */
  425.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  426.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  427.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  428.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  429.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  430.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  431.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  432.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  433.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  434.     long                             scsiReserved3;                /* reserved                                */
  435.  
  436.     UInt16                             scsiEngineCount;            /* <- Number of engines on HBA                         */
  437.     UInt16                             scsiMaxTransferType;        /* <- Number of transfer types for this HBA            */
  438.  
  439.     UInt32                             scsiDataTypes;                /* <- which data types are supported by this SIM     */
  440.  
  441.     UInt16                             scsiIOpbSize;                /* <- Size of SCSI_IO PB for this SIM/HBA             */
  442.     UInt16                             scsiMaxIOpbSize;            /* <- Size of max SCSI_IO PB for all SIM/HBAs         */
  443.  
  444.     UInt32                             scsiFeatureFlags;            /* <- Supported features flags field                 */
  445.  
  446.     UInt8                             scsiVersionNumber;            /* <- Version number for the SIM/HBA                 */
  447.     UInt8                             scsiHBAInquiry;                /* <- Mimic of INQ byte 7 for the HBA                 */
  448.     UInt8                             scsiTargetModeFlags;        /* <- Flags for target mode support                 */
  449.     UInt8                             scsiScanFlags;                /* <- Scan related feature flags                     */
  450.  
  451.     UInt32                             scsiSIMPrivatesPtr;            /* <- Ptr to SIM private data area                     */
  452.     UInt32                             scsiSIMPrivatesSize;        /* <- Size of SIM private data area                 */
  453.     UInt32                             scsiAsyncFlags;                /* <- Event cap. for Async Callback                 */
  454.  
  455.     UInt8                             scsiHiBusID;                /* <- Highest path ID in the subsystem              */
  456.     UInt8                             scsiInitiatorID;            /* <- ID of the HBA on the SCSI bus                 */
  457.     UInt16                             scsiBIReserved0;            /*                                                    */
  458.  
  459.     UInt32                             scsiBIReserved1;            /* <-                                                  */
  460.     UInt32                             scsiFlagsSupported;            /* <- which scsiFlags are supported                 */
  461.  
  462.     UInt16                             scsiIOFlagsSupported;        /* <- which scsiIOFlags are supported                 */
  463.     UInt16                             scsiWeirdStuff;                /* <-                                                 */
  464.     UInt16                             scsiMaxTarget;                /* <- maximum Target number supported                 */
  465.     UInt16                             scsiMaxLUN;                    /* <- maximum Logical Unit number supported         */
  466.  
  467.     char                             scsiSIMVendor[16];            /* <- Vendor ID of SIM (or XPT if bus<FF)         */
  468.     char                             scsiHBAVendor[16];            /* <- Vendor ID of the HBA                         */
  469.     char                             scsiControllerFamily[16];    /* <- Family of SCSI Controller                 */
  470.     char                             scsiControllerType[16];        /* <- Specific Model of SCSI Controller used     */
  471.  
  472.     char                             scsiXPTversion[4];            /* <- version number of XPT                         */
  473.     char                             scsiSIMversion[4];            /* <- version number of SIM                         */
  474.     char                             scsiHBAversion[4];            /* <- version number of HBA                         */
  475.  
  476.     UInt8                             scsiHBAslotType;            /* <- type of "slot" that this HBA is in            */
  477.     UInt8                             scsiHBAslotNumber;            /* <- slot number of this HBA                         */
  478.     UInt16                             scsiSIMsRsrcID;                /* <- resource ID of this SIM                         */
  479.  
  480.     UInt16                             scsiBIReserved3;            /* <-                                                 */
  481.     UInt16                             scsiAdditionalLength;        /* <- additional BusInquiry PB len                    */
  482. };
  483. typedef struct SCSIBusInquiryPB SCSIBusInquiryPB;
  484.  
  485. /* Abort SIM Request PB */
  486. struct SCSIAbortCommandPB {
  487.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  488.     short                             scsiReserved1;                /* ->     reserved for input                */
  489.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  490.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  491.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  492.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  493.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  494.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  495.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  496.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  497.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  498.     long                             scsiReserved3;                /* reserved                                */
  499.     SCSI_IO *                        scsiIOptr;                    /* Pointer to the PB to abort            */
  500. };
  501. typedef struct SCSIAbortCommandPB SCSIAbortCommandPB;
  502.  
  503. /* Terminate I/O Process Request PB */
  504. struct SCSITerminateIOPB {
  505.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  506.     short                             scsiReserved1;                /* ->     reserved for input                */
  507.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  508.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  509.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  510.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  511.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  512.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  513.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  514.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  515.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  516.     long                             scsiReserved3;                /* reserved                                */
  517.     SCSI_IO *                        scsiIOptr;                    /* Pointer to the PB to terminate         */
  518. };
  519. typedef struct SCSITerminateIOPB SCSITerminateIOPB;
  520.  
  521. /* Reset SCSI Bus PB */
  522. struct SCSIResetBusPB {
  523.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  524.     short                             scsiReserved1;                /* ->     reserved for input                */
  525.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  526.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  527.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  528.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  529.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  530.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  531.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  532.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  533.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  534.     long                             scsiReserved3;                /* reserved                                */
  535. };
  536. typedef struct SCSIResetBusPB SCSIResetBusPB;
  537.  
  538. /* Reset SCSI Device PB */
  539. struct SCSIResetDevicePB {
  540.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  541.     short                             scsiReserved1;                /* ->     reserved for input                */
  542.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  543.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  544.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  545.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  546.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  547.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  548.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  549.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  550.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  551.     long                             scsiReserved3;                /* reserved                                */
  552. };
  553. typedef struct SCSIResetDevicePB SCSIResetDevicePB;
  554.  
  555. /* Release SIM Queue PB */
  556. struct SCSIReleaseQPB {
  557.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  558.     short                             scsiReserved1;                /* ->     reserved for input                */
  559.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  560.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  561.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  562.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  563.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  564.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  565.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  566.     BytePtr                         scsiDriverStorage;            /* <> Ptr for driver private use        */
  567.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  568.     long                             scsiReserved3;                /* reserved                                */
  569. };
  570. typedef struct SCSIReleaseQPB SCSIReleaseQPB;
  571.  
  572. /* SCSI Get Virtual ID Info PB */
  573. struct SCSIGetVirtualIDInfoPB {
  574.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  575.     short                             scsiReserved1;                /* ->     reserved for input                */
  576.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  577.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  578.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  579.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  580.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  581.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  582.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  583.     Ptr                             scsiDriverStorage;            /* <> Ptr for driver private use        */
  584.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  585.     long                             scsiReserved3;                /* reserved                                */
  586.     UInt16                             scsiOldCallID;                /* -> SCSI ID of device in question     */
  587.     Boolean                         scsiExists;                    /* <- true if device exists             */
  588.     SInt8                             filler;
  589. };
  590. typedef struct SCSIGetVirtualIDInfoPB SCSIGetVirtualIDInfoPB;
  591.  
  592. /* Create/Lookup/Remove RefNum for Device PB */
  593. struct SCSIDriverPB {
  594.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  595.     short                             scsiReserved1;                /* ->     reserved for input                */
  596.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  597.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  598.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  599.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  600.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  601.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  602.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  603.     Ptr                             scsiDriverStorage;            /* <> Ptr for driver private use        */
  604.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  605.     long                             scsiReserved3;                /* reserved                                */
  606.     short                             scsiDriver;                    /* -> DriverRefNum, For SetDriver, <- For GetNextDriver */
  607.     UInt16                             scsiDriverFlags;            /* <> Details of driver/device             */
  608.     DeviceIdent                     scsiNextDevice;                /* <- DeviceIdent of the NEXT Item in the list  */
  609. };
  610. typedef struct SCSIDriverPB SCSIDriverPB;
  611.  
  612. /* Load Driver PB */
  613. struct SCSILoadDriverPB {
  614.     SCSIHdr *                        qLink;                        /* (internal use, must be nil on entry)    */
  615.     short                             scsiReserved1;                /* ->     reserved for input                */
  616.     UInt16                             scsiPBLength;                /* -> Length of the entire PB            */
  617.     UInt8                             scsiFunctionCode;            /* -> function selector                 */
  618.     UInt8                             scsiReserved2;                /* <-     reserved for output                */
  619.     volatile OSErr                     scsiResult;                    /* <- Returned result                     */
  620.     DeviceIdent                     scsiDevice;                    /* -> Device Identifier (bus+target+lun)*/
  621.     SCSICallbackUPP                 scsiCompletion;                /* -> Callback on completion function      */
  622.     UInt32                             scsiFlags;                    /* -> assorted flags                    */
  623.     Ptr                             scsiDriverStorage;            /* <> Ptr for driver private use        */
  624.     Ptr                             scsiXPTprivate;                /* private field for use in XPT            */
  625.     long                             scsiReserved3;                /* reserved                                */
  626.     short                             scsiLoadedRefNum;            /* <- SIM returns refnum of driver         */
  627.     Boolean                         scsiDiskLoadFailed;            /* -> if true, indicates call after failure to load */
  628.     SInt8                             filler;
  629. };
  630. typedef struct SCSILoadDriverPB SCSILoadDriverPB;
  631.  
  632.  
  633. /* Defines for the scsiTransferType field */
  634.  
  635. enum {
  636.     scsiTransferBlind            = 0,
  637.     scsiTransferPolled            = 1
  638. };
  639.  
  640.  
  641. enum {
  642.     scsiErrorBase                = -7936
  643. };
  644.  
  645.  
  646. enum {
  647.     scsiRequestInProgress        = 1,                            /* 1     = PB request is in progress             */
  648.                                                                 /* Execution failed  00-2F */
  649.     scsiRequestAborted            = scsiErrorBase + 2,            /* -7934 = PB request aborted by the host         */
  650.     scsiUnableToAbort            = scsiErrorBase + 3,            /* -7933 = Unable to Abort PB request             */
  651.     scsiNonZeroStatus            = scsiErrorBase + 4,            /* -7932 = PB request completed with an err     */
  652.     scsiUnused05                = scsiErrorBase + 5,            /* -7931 =                                      */
  653.     scsiUnused06                = scsiErrorBase + 6,            /* -7930 =                                      */
  654.     scsiUnused07                = scsiErrorBase + 7,            /* -7929 =                                      */
  655.     scsiUnused08                = scsiErrorBase + 8,            /* -7928 =                                      */
  656.     scsiUnableToTerminate        = scsiErrorBase + 9,            /* -7927 = Unable to Terminate I/O PB req         */
  657.     scsiSelectTimeout            = scsiErrorBase + 10,            /* -7926 = Target selection timeout             */
  658.     scsiCommandTimeout            = scsiErrorBase + 11,            /* -7925 = Command timeout                      */
  659.     scsiIdentifyMessageRejected    = scsiErrorBase + 12,            /* -7924 =                                      */
  660.     scsiMessageRejectReceived    = scsiErrorBase + 13,            /* -7923 = Message reject received                 */
  661.     scsiSCSIBusReset            = scsiErrorBase + 14,            /* -7922 = SCSI bus reset sent/received         */
  662.     scsiParityError                = scsiErrorBase + 15,            /* -7921 = Uncorrectable parity error occured     */
  663.     scsiAutosenseFailed            = scsiErrorBase + 16,            /* -7920 = Autosense: Request sense cmd fail     */
  664.     scsiUnused11                = scsiErrorBase + 17,            /* -7919 =                                      */
  665.     scsiDataRunError            = scsiErrorBase + 18,            /* -7918 = Data overrun/underrun error          */
  666.     scsiUnexpectedBusFree        = scsiErrorBase + 19,            /* -7917 = Unexpected BUS free                     */
  667.     scsiSequenceFailed            = scsiErrorBase + 20,            /* -7916 = Target bus phase sequence failure     */
  668.     scsiWrongDirection            = scsiErrorBase + 21,            /* -7915 = Data phase was in wrong direction     */
  669.     scsiUnused16                = scsiErrorBase + 22,            /* -7914 =                                      */
  670.     scsiBDRsent                    = scsiErrorBase + 23,            /* -7913 = A SCSI BDR msg was sent to target     */
  671.     scsiTerminated                = scsiErrorBase + 24,            /* -7912 = PB request terminated by the host     */
  672.     scsiNoNexus                    = scsiErrorBase + 25,            /* -7911 = Nexus is not established             */
  673.     scsiCDBReceived                = scsiErrorBase + 26,            /* -7910 = The SCSI CDB has been received         */
  674.                                                                 /* Couldn't begin execution  30-3F */
  675.     scsiTooManyBuses            = scsiErrorBase + 48,            /* -7888 = Register failed because we're full    */
  676.     scsiBusy                    = scsiErrorBase + 49,            /* -7887 = SCSI subsystem is busy                 */
  677.     scsiProvideFail                = scsiErrorBase + 50,            /* -7886 = Unable to provide requ. capability    */
  678.     scsiDeviceNotThere            = scsiErrorBase + 51,            /* -7885 = SCSI device not installed/there      */
  679.     scsiNoHBA                    = scsiErrorBase + 52,            /* -7884 = No HBA detected Error                 */
  680.     scsiDeviceConflict            = scsiErrorBase + 53,            /* -7883 = sorry, max 1 refNum per DeviceIdent     */
  681.     scsiNoSuchXref                = scsiErrorBase + 54,            /* -7882 = no such RefNum xref                     */
  682.     scsiQLinkInvalid            = scsiErrorBase + 55,            /* -7881 = pre-linked PBs not supported            */
  683.                                                                 /*   (The QLink field was nonzero)                */
  684.                                                                 /* Parameter errors  40-7F */
  685.     scsiPBLengthError            = scsiErrorBase + 64,            /* -7872 = (scsiPBLength is insuf'ct/invalid     */
  686.     scsiFunctionNotAvailable    = scsiErrorBase + 65,            /* -7871 = The requ. func is not available      */
  687.     scsiRequestInvalid            = scsiErrorBase + 66,            /* -7870 = PB request is invalid                 */
  688.     scsiBusInvalid                = scsiErrorBase + 67,            /* -7869 = Bus ID supplied is invalid              */
  689.     scsiTIDInvalid                = scsiErrorBase + 68,            /* -7868 = Target ID supplied is invalid         */
  690.     scsiLUNInvalid                = scsiErrorBase + 69,            /* -7867 = LUN supplied is invalid              */
  691.     scsiIDInvalid                = scsiErrorBase + 70,            /* -7866 = The initiator ID is invalid          */
  692.     scsiDataTypeInvalid            = scsiErrorBase + 71,            /* -7865 = scsiDataType requested not supported */
  693.     scsiTransferTypeInvalid        = scsiErrorBase + 72,            /* -7864 = scsiTransferType field is too high     */
  694.     scsiCDBLengthInvalid        = scsiErrorBase + 73            /* -7863 = scsiCDBLength field is too big         */
  695. };
  696.  
  697. /* New errors for SCSI Family         */
  698.  
  699. enum {
  700.     scsiUnused74                = scsiErrorBase + 74,            /* -7862 =                                          */
  701.     scsiUnused75                = scsiErrorBase + 75,            /* -7861 =                                         */
  702.     scsiBadDataLength            = scsiErrorBase + 76,            /* -7860 = a zero data length in PB             */
  703.     scsiPartialPrepared            = scsiErrorBase + 77,            /* -7859 = could not do full prepare mem for I/O*/
  704.     scsiInvalidMsgType            = scsiErrorBase + 78,            /* -7858 = Invalid message type (internal)        */
  705.     scsiUnused79                = scsiErrorBase + 79,            /* -7857 =                                           */
  706.     scsiBadConnID                = scsiErrorBase + 80,            /* -7856 = Bad Connection ID                      */
  707.     scsiUnused81                = scsiErrorBase + 81,            /* -7855 =                                         */
  708.     scsiIOInProgress            = scsiErrorBase + 82,            /* -7854 = Can't close conn, IO in prog            */
  709.     scsiTargetReserved            = scsiErrorBase + 83,            /* -7853 = Target already reserved                */
  710.     scsiUnused84                = scsiErrorBase + 84,            /* -7852 =                                         */
  711.     scsiUnused85                = scsiErrorBase + 85,            /* -7851 =                                         */
  712.     scsiBadConnType                = scsiErrorBase + 86,            /* -7850 = Bad connection type                    */
  713.     scsiCannotLoadPlugin        = scsiErrorBase + 87            /* -7849 = No matching service category            */
  714. };
  715.  
  716. /* +++ */
  717. /*
  718.  * scsiFamilyInternalError and scsiPluginInternalError are intended to handle consistency check failures.
  719.  * For example, if the family stores a record on a lookaside queue, but does not find that record
  720.  * it can use this error to report this failure. SCSI Manager 4.3 uses dsIOCoreErr in a few places,
  721.  * but this is probably not the best error. In general, internal errors should be reported as bugs.
  722.  *
  723.  * The following range of errors is provided for third-party (non-Apple) SCSI SIM and device driver vendors.
  724.  * In general, they would be used for error conditions that are not covered by the standardized errors.
  725.  * They should not normally be conveyed to normal applications, but might be used for communication between
  726.  * a plug-in and a vendor-provided device driver (for example, to manage RAID hot-swapping).
  727.  *
  728.  * Note: I don't know how many SCSI errors are reserved in the error code architecture. Don't assume that
  729.  * we'll actually get sixteen, but we should reserve at least one.
  730.  */
  731.  
  732. enum {
  733.     scsiFamilyInternalError        = scsiErrorBase + 87,            /* -7849 = Internal consistency check failed    */
  734.     scsiPluginInternalError        = scsiErrorBase + 88,            /* -7848 = Internal consistency check failed    */
  735.     scsiVendorSpecificErrorBase    = scsiErrorBase + 128,            /* ??    = Start of third-party error range        */
  736.     scsiVendorSpecificErrorCount = 16                            /* Number of third-party errors                    */
  737. };
  738.  
  739. /* --- */
  740.  
  741. enum {
  742.     scsiExecutionErrors            = scsiErrorBase,
  743.     scsiNotExecutedErrors        = scsiTooManyBuses,
  744.     scsiParameterErrors            = scsiPBLengthError
  745. };
  746.  
  747. /* Defines for the scsiResultFlags field */
  748.  
  749. enum {
  750.     scsiSIMQFrozen                = 0x0001,                        /* The SIM queue is frozen w/this err            */
  751.     scsiAutosenseValid            = 0x0002,                        /* Autosense data valid for target              */
  752.     scsiBusNotFree                = 0x0004                        /* At time of callback, SCSI bus is not free    */
  753. };
  754.  
  755. /* Defines for the bit numbers of the scsiFlags field in the PB header for the SCSIExecIO function */
  756.  
  757. enum {
  758.     kbSCSIDisableAutosense        = 29,                            /* Disable auto sense feature                     */
  759.     kbSCSIFlagReservedA            = 28,                            /*                                              */
  760.     kbSCSIFlagReserved0            = 27,                            /*                                              */
  761.     kbSCSICDBLinked                = 26,                            /* The PB contains a linked CDB                    */
  762.     kbSCSIQEnable                = 25,                            /* Target queue actions are enabled                */
  763.     kbSCSICDBIsPointer            = 24,                            /* The CDB field contains a pointer                */
  764.     kbSCSIFlagReserved1            = 23,                            /*                                                 */
  765.     kbSCSIInitiateSyncData        = 22,                            /* Attempt Sync data xfer and SDTR                */
  766.     kbSCSIDisableSyncData        = 21,                            /* Disable sync, go to async                    */
  767.     kbSCSISIMQHead                = 20,                            /* Place PB at the head of SIM Q                */
  768.     kbSCSISIMQFreeze            = 19,                            /* Return the SIM Q to frozen state                */
  769.     kbSCSISIMQNoFreeze            = 18,                            /* Disallow SIM Q freezing                        */
  770.     kbSCSIDoDisconnect            = 17,                            /* Definitely do disconnect                        */
  771.     kbSCSIDontDisconnect        = 16,                            /* Definitely don't disconnect                    */
  772.     kbSCSIDataReadyForDMA        = 15,                            /* Data buffer(s) are ready for DMA                */
  773.     kbSCSIFlagReserved3            = 14,                            /*                                                 */
  774.     kbSCSIDataPhysical            = 13,                            /* SG/Buffer data ptrs are physical                */
  775.     kbSCSISensePhysical            = 12,                            /* Autosense buffer ptr is physical                */
  776.     kbSCSIFlagReserved5            = 11,                            /*                                                 */
  777.     kbSCSIFlagReserved6            = 10,                            /*                                                 */
  778.     kbSCSIFlagReserved7            = 9,                            /*                                                 */
  779.     kbSCSIFlagReserved8            = 8,                            /*                                                 */
  780.     kbSCSIDataBufferValid        = 7,                            /* Data buffer valid                            */
  781.     kbSCSIStatusBufferValid        = 6,                            /* Status buffer valid                             */
  782.     kbSCSIMessageBufferValid    = 5,                            /* Message buffer valid                            */
  783.     kbSCSIFlagReserved9            = 4                                /*                                              */
  784. };
  785.  
  786. /* Defines for the bit masks of the scsiFlags field */
  787.  
  788. enum {
  789.     scsiDirectionMask            = (long)0xC0000000,                /* Data direction mask                        */
  790.     scsiDirectionNone            = (long)0xC0000000,                /* Data direction (11: no data)                */
  791.     scsiDirectionReserved        = 0x00000000,                    /* Data direction (00: reserved)            */
  792.     scsiDirectionOut            = (long)0x80000000,                /* Data direction (10: DATA OUT)            */
  793.     scsiDirectionIn                = 0x40000000,                    /* Data direction (01: DATA IN)                */
  794.     scsiDisableAutosense        = 0x20000000,                    /* Disable auto sense feature                */
  795.     scsiFlagReservedA            = 0x10000000,                    /*                                             */
  796.     scsiFlagReserved0            = 0x08000000,                    /*                                             */
  797.     scsiCDBLinked                = 0x04000000,                    /* The PB contains a linked CDB                */
  798.     scsiQEnable                    = 0x02000000,                    /* Target queue actions are enabled            */
  799.     scsiCDBIsPointer            = 0x01000000,                    /* The CDB field contains a pointer            */
  800.     scsiFlagReserved1            = 0x00800000,                    /*                                             */
  801.     scsiInitiateSyncData        = 0x00400000,                    /* Attempt Sync data xfer and SDTR            */
  802.     scsiDisableSyncData            = 0x00200000,                    /* Disable sync, go to async                */
  803.     scsiSIMQHead                = 0x00100000,                    /* Place PB at the head of SIM Q            */
  804.     scsiSIMQFreeze                = 0x00080000,                    /* Return the SIM Q to frozen state            */
  805.     scsiSIMQNoFreeze            = 0x00040000,                    /* Disallow SIM Q freezing                    */
  806.     scsiDoDisconnect            = 0x00020000,                    /* Definitely do disconnect                    */
  807.     scsiDontDisconnect            = 0x00010000,                    /* Definitely don't disconnect                */
  808.     scsiDataReadyForDMA            = 0x00008000,                    /* Data buffer(s) are ready for DMA            */
  809.     scsiFlagReserved3            = 0x00004000,                    /*  */
  810.     scsiDataPhysical            = 0x00002000,                    /* SG/Buffer data ptrs are physical            */
  811.     scsiSensePhysical            = 0x00001000,                    /* Autosense buffer ptr is physical            */
  812.     scsiFlagReserved5            = 0x00000800,                    /*                                          */
  813.     scsiFlagReserved6            = 0x00000400,                    /*                                             */
  814.     scsiFlagReserved7            = 0x00000200,                    /*                                             */
  815.     scsiFlagReserved8            = 0x00000100                    /*                                             */
  816. };
  817.  
  818. /* bit masks for the scsiIOFlags field in SCSIExecIOPB */
  819.  
  820. enum {
  821.     scsiNoParityCheck            = 0x0002,                        /* disable parity checking                             */
  822.     scsiDisableSelectWAtn        = 0x0004,                        /* disable select w/Atn                              */
  823.     scsiSavePtrOnDisconnect        = 0x0008,                        /* do SaveDataPointer upon Disconnect msg             */
  824.     scsiNoBucketIn                = 0x0010,                        /* don’t bit bucket in during this I/O                 */
  825.     scsiNoBucketOut                = 0x0020,                        /* don’t bit bucket out during this I/O             */
  826.     scsiDisableWide                = 0x0040,                        /* disable wide transfer negotiation                 */
  827.     scsiInitiateWide            = 0x0080,                        /* initiate wide transfer negotiation                 */
  828.     scsiRenegotiateSense        = 0x0100,                        /* renegotiate sync/wide before issuing autosense     */
  829.     scsiDisableDiscipline        = 0x0200,                        /* disable parameter checking on SCSIExecIO calls    */
  830.     scsiIOFlagReserved0080        = 0x0080,                        /*                                                  */
  831.     scsiIOFlagReserved8000        = 0x8000                        /*                                                     */
  832. };
  833.  
  834. /* Defines for the Bus Inquiry PB fields. */
  835. /* scsiHBAInquiry field bits */
  836.  
  837. enum {
  838.     scsiBusMDP                    = 0x80,                            /* Supports Modify Data Pointer message                        */
  839.     scsiBusWide32                = 0x40,                            /* Supports 32 bit wide SCSI                                */
  840.     scsiBusWide16                = 0x20,                            /* Supports 16 bit wide SCSI                                */
  841.     scsiBusSDTR                    = 0x10,                            /* Supports Sync Data Transfer Req message                    */
  842.     scsiBusLinkedCDB            = 0x08,                            /* Supports linked CDBs                                        */
  843.     scsiBusTagQ                    = 0x02,                            /* Supports tag queue message                                */
  844.     scsiBusSoftReset            = 0x01                            /* Supports soft reset                                        */
  845. };
  846.  
  847. /* Defines for the scsiDataType field */
  848.  
  849. enum {
  850.     scsiDataBuffer                = 0,                            /* single contiguous buffer supplied                  */
  851.     scsiDataTIB                    = 1,                            /* TIB supplied (ptr in scsiDataPtr)                 */
  852.     scsiDataSG                    = 2,                            /* scatter/gather list supplied                      */
  853.     scsiDataIOTable                = 3                                /*#(7/11/95) Prepared by Block Storage              */
  854. };
  855.  
  856. /* scsiDataTypes field bits  */
  857. /*    bits 0->15 Apple-defined, 16->30 3rd-party unique, 31 = reserved */
  858.  
  859. enum {
  860.     scsiBusDataTIB                = (1 << scsiDataTIB),            /* TIB supplied (ptr in scsiDataPtr)        */
  861.     scsiBusDataBuffer            = (1 << scsiDataBuffer),        /* single contiguous buffer supplied         */
  862.     scsiBusDataSG                = (1 << scsiDataSG),            /* scatter/gather list supplied             */
  863.     scsiBusDataIOTable            = (1 << scsiDataIOTable),        /* (2/6/95) Prepare Memory for IO*/
  864.     scsiBusDataReserved            = (long)0x80000000                /*                                           */
  865. };
  866.  
  867. /* scsiScanFlags field bits */
  868.  
  869. enum {
  870.     scsiBusScansDevices            = 0x80,                            /* Bus scans for and maintains device list            */
  871.     scsiBusScansOnInit            = 0x40,                            /* Bus scans performed at power-up/reboot            */
  872.     scsiBusLoadsROMDrivers        = 0x20                            /* may load ROM drivers to support targets             */
  873. };
  874.  
  875. /* scsiFeatureFlags field bits */
  876.  
  877. enum {
  878.     scsiBusInternalExternalMask    = 0x000000C0,                    /* bus internal/external mask                    */
  879.     scsiBusInternalExternalUnknown = 0x00000000,                /* not known whether bus is inside or outside     */
  880.     scsiBusInternalExternal        = 0x000000C0,                    /* bus goes inside and outside the box             */
  881.     scsiBusInternal                = 0x00000080,                    /* bus goes inside the box                         */
  882.     scsiBusExternal                = 0x00000040,                    /* bus goes outside the box                     */
  883.     scsiBusCacheCoherentDMA        = 0x00000020,                    /* DMA is cache coherent                         */
  884.     scsiBusOldCallCapable        = 0x00000010,                    /* SIM is old call capable                         */
  885.     scsiBusDifferential            = 0x00000004,                    /* Single Ended (0) or Differential (1)         */
  886.     scsiBusFastSCSI                = 0x00000002,                    /* HBA supports fast SCSI                         */
  887.     scsiBusDMAavailable            = 0x00000001                    /* DMA is available                             */
  888. };
  889.  
  890. /* scsiWeirdStuff field bits */
  891.  
  892. enum {
  893.     scsiOddDisconnectUnsafeRead1 = 0x0001,                        /* Disconnects on odd byte boundries are unsafe with DMA and/or blind reads */
  894.     scsiOddDisconnectUnsafeWrite1 = 0x0002,                        /* Disconnects on odd byte boundries are unsafe with DMA and/or blind writes */
  895.     scsiBusErrorsUnsafe            = 0x0004,                        /* Non-handshaked delays or disconnects during blind transfers may cause a crash */
  896.     scsiRequiresHandshake        = 0x0008,                        /* Non-handshaked delays or disconnects during blind transfers may cause data corruption */
  897.     scsiTargetDrivenSDTRSafe    = 0x0010,                        /* Targets which initiate synchronous negotiations are supported */
  898.     scsiOddCountForPhysicalUnsafe = 0x0020,                        /* If using physical addrs all counts must be even, and disconnects must be on even boundries */
  899.     scsiAbortCmdFixed            = 0x0040,                        /* Set if abort command is fixed to properly make callbacks */
  900.     scsiMeshACKTimingFixed        = 0x0080                        /* Set if bug allowing Mesh to release ACK prematurely is fixed */
  901. };
  902.  
  903. /* scsiHBAslotType values */
  904.  
  905. enum {
  906.     scsiMotherboardBus            = 0x00,                            /* A built in Apple supplied bus                     */
  907.     scsiNuBus                    = 0x01,                            /* A SIM on a NuBus card                             */
  908.     scsiPDSBus                    = 0x03,                            /*    "  on a PDS card                                */
  909.     scsiPCIBus                    = 0x04,                            /*    "  on a PCI bus card                            */
  910.     scsiPCMCIABus                = 0x05,                            /*    "  on a PCMCIA card                            */
  911.     scsiFireWireBridgeBus        = 0x06                            /*    "  connected through a FireWire bridge        */
  912. };
  913.  
  914. /* Defines for the scsiDriverFlags field (in SCSIDriverPB) */
  915.  
  916. enum {
  917.     scsiDeviceSensitive            = 0x0001,                        /* Only driver should access this device                */
  918.     scsiDeviceNoOldCallAccess    = 0x0002                        /* no old call access to this device                     */
  919. };
  920.  
  921. /*  SIMInitInfo PB */
  922. /* directions are for SCSIRegisterBus call ( -> parm, <- result)             */
  923. struct SIMInitInfo {
  924.     Ptr                             SIMstaticPtr;                /* <- alloc. ptr to the SIM's static vars                 */
  925.     long                             staticSize;                    /* -> num bytes SIM needs for static vars                 */
  926.     SIMInitUPP                         SIMInit;                    /* -> pointer to the SIM init routine                     */
  927.     SIMActionUPP                     SIMAction;                    /* -> pointer to the SIM action routine                 */
  928.     SCSIInterruptUPP                 SIM_ISR;                    /*       reserved                                             */
  929.     SCSIInterruptUPP                 SIMInterruptPoll;            /* -> pointer to the SIM interrupt poll routine            */
  930.     SIMActionUPP                     NewOldCall;                    /* -> pointer to the SIM NewOldCall routine                */
  931.     UInt16                             ioPBSize;                    /* -> size of SCSI_IO_PBs required for this SIM            */
  932.     Boolean                         oldCallCapable;                /* -> true if this SIM can handle old-API calls            */
  933.     UInt8                             simInfoUnused1;                /*       reserved                                            */
  934.     long                             simInternalUse;                /* xx not affected or viewed by XPT                        */
  935.     SCSIUPP                         XPT_ISR;                    /*    reserved                                            */
  936.     SCSIUPP                         EnteringSIM;                /* <- ptr to the EnteringSIM routine                    */
  937.     SCSIUPP                         ExitingSIM;                    /* <- ptr to the ExitingSIM routine                        */
  938.     SCSIMakeCallbackUPP             MakeCallback;                /* <- the XPT layer’s SCSIMakeCallback routine            */
  939.     UInt16                             busID;                        /* <- bus number for the registered bus                    */
  940.     UInt8                             simSlotNumber;                /* <- Magic cookie to place in scsiHBASlotNumber (PCI)    */
  941.     UInt8                             simSRsrcID;                    /* <- Magic cookie to place in scsiSIMsRsrcID     (PCI)    */
  942.     Ptr                             simRegEntry;                /* -> The SIM's RegEntryIDPtr                     (PCI)    */
  943. };
  944. typedef struct SIMInitInfo SIMInitInfo;
  945.  
  946. /* Glue between SCSI calls and SCSITrap format */
  947.  
  948. enum {
  949.     xptSCSIAction                = 0x0001,
  950.     xptSCSIRegisterBus            = 0x0002,
  951.     xptSCSIDeregisterBus        = 0x0003,
  952.     xptSCSIReregisterBus        = 0x0004,
  953.     xptSCSIKillXPT                = 0x0005,                        /* kills Mini-XPT after transition */
  954.     xptSCSIInitialize            = 0x000A                        /* Initialize the SCSI manager */
  955. };
  956.  
  957. /*
  958.  * SCSI bus status. These values are returned by the SCSI target in the status phase.
  959.  * They are not related to Macintosh status values (except that values other than
  960.  * scsiStatusGood will result in scsiResult set to scsiNonZeroStatus).
  961.  */
  962.  
  963. enum {
  964.     scsiStatGood                = 0x00,                            /* Good Status*/
  965.     scsiStatCheckCondition        = 0x02,                            /* Check Condition*/
  966.     scsiStatConditionMet        = 0x04,                            /* Condition Met*/
  967.     scsiStatBusy                = 0x08,                            /* Busy*/
  968.     scsiStatIntermediate        = 0x10,                            /* Intermediate*/
  969.     scsiStatIntermedMet            = 0x14,                            /* Intermediate - Condition Met*/
  970.     scsiStatResvConflict        = 0x18,                            /* Reservation conflict*/
  971.     scsiStatTerminated            = 0x22,                            /* Command terminated*/
  972.     scsiStatQFull                = 0x28                            /* Queue full*/
  973. };
  974.  
  975. /* SCSI messages*/
  976.  
  977. enum {
  978.     kCmdCompleteMsg                = 0,
  979.     kExtendedMsg                = 1,                            /* 0x01*/
  980.     kSaveDataPointerMsg            = 2,                            /* 0x02*/
  981.     kRestorePointersMsg            = 3,                            /* 0x03*/
  982.     kDisconnectMsg                = 4,                            /* 0x04*/
  983.     kInitiatorDetectedErrorMsg    = 5,                            /* 0x05*/
  984.     kAbortMsg                    = 6,                            /* 0x06*/
  985.     kMsgRejectMsg                = 7,                            /* 0x07*/
  986.     kNoOperationMsg                = 8,                            /* 0x08*/
  987.     kMsgParityErrorMsg            = 9,                            /* 0x09*/
  988.     kLinkedCmdCompleteMsg        = 10,                            /* 0x0a*/
  989.     kLinkedCmdCompleteWithFlagMsg = 11,                            /* 0x0b*/
  990.     kBusDeviceResetMsg            = 12,                            /* 0x0c*/
  991.     kAbortTagMsg                = 13,                            /* 0x0d*/
  992.     kClearQueueMsg                = 14,                            /* 0x0e*/
  993.     kInitiateRecoveryMsg        = 15,                            /* 0x0f*/
  994.     kReleaseRecoveryMsg            = 16,                            /* 0x10*/
  995.     kTerminateIOProcessMsg        = 17,                            /* 0x11*/
  996.     kSimpleQueueTag                = 0x20,                            /* 0x20*/
  997.     kHeadOfQueueTagMsg            = 0x21,                            /* 0x21*/
  998.     kOrderedQueueTagMsg            = 0x22,                            /* 0x22*/
  999.     kIgnoreWideResidueMsg        = 0x23                            /* 0x23*/
  1000. };
  1001.  
  1002.  
  1003. /* moveq #kSCSIx, D0;  _SCSIAtomic */
  1004.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  1005.                                                                                             #pragma parameter __D0 SCSIAction(__A0)
  1006.                                                                                             #endif
  1007. EXTERN_API( OSErr )
  1008. SCSIAction                        (SCSI_PB *                parameterBlock)                        TWOWORDINLINE(0x7001, 0xA089);
  1009.  
  1010.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  1011.                                                                                             #pragma parameter __D0 SCSIRegisterBus(__A0)
  1012.                                                                                             #endif
  1013. EXTERN_API( OSErr )
  1014. SCSIRegisterBus                    (SIMInitInfo *            parameterBlock)                        TWOWORDINLINE(0x7002, 0xA089);
  1015.  
  1016.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  1017.                                                                                             #pragma parameter __D0 SCSIDeregisterBus(__A0)
  1018.                                                                                             #endif
  1019. EXTERN_API( OSErr )
  1020. SCSIDeregisterBus                (SCSI_PB *                parameterBlock)                        TWOWORDINLINE(0x7003, 0xA089);
  1021.  
  1022.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  1023.                                                                                             #pragma parameter __D0 SCSIReregisterBus(__A0)
  1024.                                                                                             #endif
  1025. EXTERN_API( OSErr )
  1026. SCSIReregisterBus                (SIMInitInfo *            parameterBlock)                        TWOWORDINLINE(0x7004, 0xA089);
  1027.  
  1028.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  1029.                                                                                             #pragma parameter __D0 SCSIKillXPT(__A0)
  1030.                                                                                             #endif
  1031. EXTERN_API( OSErr )
  1032. SCSIKillXPT                        (SIMInitInfo *            parameterBlock)                        TWOWORDINLINE(0x7005, 0xA089);
  1033.  
  1034.  
  1035.  
  1036. #if PRAGMA_STRUCT_ALIGN
  1037.     #pragma options align=reset
  1038. #elif PRAGMA_STRUCT_PACKPUSH
  1039.     #pragma pack(pop)
  1040. #elif PRAGMA_STRUCT_PACK
  1041.     #pragma pack()
  1042. #endif
  1043.  
  1044. #ifdef PRAGMA_IMPORT_OFF
  1045. #pragma import off
  1046. #elif PRAGMA_IMPORT
  1047. #pragma import reset
  1048. #endif
  1049.  
  1050. #ifdef __cplusplus
  1051. }
  1052. #endif
  1053.  
  1054. #endif /* __SCSI__ */
  1055.  
  1056.